// ===========对请求函数进行简单的封装=========

import {reactive,toRefs} from 'vue'
import axios from 'axios'

function useURLLoader (url:string) {
    const urlLoaderDate = reactive({
        result: null,
        loading: true,
        loaded: false,
        error: null
    })
    const urlLoaderToRefsDate = toRefs(urlLoaderDate)
    axios.get(url).then(res => {
        urlLoaderDate.loading = false,
        urlLoaderDate.loaded = true,
        urlLoaderDate.result = res.data
    }).catch(err => {
        urlLoaderDate.error = err
        urlLoaderDate.loading = false
    })

    return {
        ...urlLoaderToRefsDate
    }
}

export default useURLLoader